package edu.cmu.vlis.datamining.SimilarityFeatures;

import java.util.HashSet;
import java.util.Set;

import org.jgrapht.alg.NeighborIndex;

import edu.cmu.vlis.datamining.core.Edge;
import edu.cmu.vlis.datamining.core.Feature;
import edu.cmu.vlis.datamining.core.IFeatureCalculator;
import edu.cmu.vlis.datamining.core.Vertex;

public class AdamicAldarMeasure implements IFeatureCalculator {

    private NeighborIndex<Vertex, Edge> neighborIndex;
    private int featueId;
    
    public AdamicAldarMeasure(NeighborIndex<Vertex, Edge> nIndx) {
        
        this.neighborIndex = nIndx;
        this.featueId = 0;
    }
    public Feature compute(Vertex a, Vertex b) {
        
            Set<Vertex> neighborsA = new HashSet<Vertex>(this.neighborIndex.neighborsOf(a));
            Set<Vertex> neighborsB = this.neighborIndex.neighborsOf(b);
            
            neighborsA.retainAll(neighborsB);
            
            float score = 0f;
            
            for(Vertex commonNeighbor : neighborsA)
                score += 1/Math.log(this.neighborIndex.neighborsOf(commonNeighbor).size());
            
            return new Feature(this.featueId,score);
    }

}
